package com.matrix.draft.sockettest.newprotocoltcp.handler;

import com.matrix.draft.sockettest.newprotocoltcp.pojo.MyMessage;
import com.matrix.draft.sockettest.newprotocoltcp.pojo.StringMessage;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class ClientHandler extends SimpleChannelInboundHandler<MyMessage> {
    // 根据MyMessage协议发送数据
    @Override
    public void channelActive(ChannelHandlerContext ctx) {
        // 发送一个affairType为1的StringMessage消息
        ctx.pipeline().writeAndFlush(new StringMessage("你好啊自定义超级协议"));
    }

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, MyMessage msg) throws Exception {
        log.debug("Client Receiving : {}", msg.getContent());
    }
}
